package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Spicymaster;
import com.restaurant.service.SpicymasterService;

public class SpicymasterServiceImpl implements SpicymasterService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Spicymaster addOrModify( Spicymaster objSpicymaster ) {
       return ( Spicymaster ) hibernateTemplate.merge( objSpicymaster );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Spicymaster deleteRecord( Spicymaster objSpicymaster ) {
       hibernateTemplate.delete( objSpicymaster );
       return objSpicymaster;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Spicymaster modifyRecord( Spicymaster objSpicymaster ) {
       return ( Spicymaster ) hibernateTemplate.merge( objSpicymaster );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Spicymaster> loadAll() {
       return (List<Spicymaster>)hibernateTemplate.findByNamedQuery( "Spicymaster.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Spicymaster loadByPrimaryKey( Long primaryKey ) {
       return (Spicymaster) hibernateTemplate.get( Spicymaster.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Spicymaster deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Spicymaster> loadByHql(String query) {
       return ( List<Spicymaster> ) hibernateTemplate.find( query );
   }
}